﻿namespace CALENDAR
{
    internal class Program
    {
        const int monthWidth = 30;
        const int monthHeight = 10;
        static void Main(string[] args)
        {
            int x = 0, y = 0;//初始位置
            int Week = 0;
            DateTime theDay = new DateTime(2022, 1, 1);
            while (theDay.Year == 2022)
                {
                if (theDay.Day == 1)//每月第一天开始
                   {
                    x = ((theDay.Month - 1) % 3) * monthWidth;
                    y = ((theDay.Month - 1) / 3) * monthHeight;//确定月份的位置，一行三个月
                    Console.SetCursorPosition(x, y);//建立坐标系，赋月份的位置
                    Console.WriteLine("{0,10}月", theDay.Month);//输出月份，0为占位符，占10字节
                    Console.SetCursorPosition(x, y + 1);
                    Console.Write("日 一 二 三 四 五 六");
                    Week = (int)theDay.DayOfWeek;//每月1号的星期数
                    }

                    int week = (int)theDay.DayOfWeek;//每天的星期数
                    Console.SetCursorPosition(x + week * 3, y + (int)Math.Ceiling((theDay.Day - 7 + Week) / 7.0) + 2);//Math.Celling取大于等于此数的最小整数:int强制转换
                    Console.WriteLine("{0,2}", theDay.Day);
                    theDay = theDay.AddDays(1);
                }
        }
    }
}